﻿using System;

namespace BackupLibrary
{
    public class EmailProcess
    {
        public bool GmailMailGonder(string Mail_From, string Mail_to, string user_name, string pwd, string subject, object body, string server)
        {
            try
            {
                System.Web.Mail.MailMessage objMail = new System.Web.Mail.MailMessage();
                objMail.To = Mail_to;
                objMail.From = "\\" + Mail_From + "\\ <" + Mail_From + ">";
                objMail.Subject = subject;
                objMail.Body = body.ToString();
                objMail.BodyFormat = System.Web.Mail.MailFormat.Html;
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtsperver", server);
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", user_name);
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", pwd);
                System.Web.Mail.SmtpMail.SmtpServer = server;
                System.Web.Mail.SmtpMail.Send(objMail);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool GmailMailGonder(string Mail_From, string Mail_to, string user_name, string pwd, string subject, string body, string server, string[] atach_file)
        {
            try
            {
                System.Web.Mail.MailMessage objMail = new System.Web.Mail.MailMessage();
                objMail.To = Mail_to;
                objMail.From = "\\" + Mail_From + "\\ <" + Mail_From + ">";
                objMail.Subject = subject;
                objMail.Body = body;
                objMail.BodyFormat = System.Web.Mail.MailFormat.Html;
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtsperver", server);
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", user_name);
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", pwd);
                for (int i = 0; i <= atach_file.Length - 1; i++)
                {
                    objMail.Attachments.Add(new System.Web.Mail.MailAttachment(atach_file[i]));
                }
                System.Web.Mail.SmtpMail.SmtpServer = server;
                System.Web.Mail.SmtpMail.Send(objMail);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool PopMailGonder(string Mail_From, string Mail_to, string user_name, string pwd, string subject, string body, string server)
        {
            try
            {
                System.Web.Mail.MailMessage objMail = new System.Web.Mail.MailMessage();
                objMail.To = Mail_to;
                objMail.From = "\\" + Mail_From + "\\ <" + Mail_From + ">";
                objMail.Subject = subject;
                objMail.Body = body;
                objMail.BodyFormat = System.Web.Mail.MailFormat.Html;
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtsperver", server);
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "25");
                //objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true")
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", user_name);
                objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", pwd);
                System.Web.Mail.SmtpMail.SmtpServer = server;
                System.Web.Mail.SmtpMail.Send(objMail);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}
